/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2023-12-07 09:26:03
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-02-25 14:51:29
 * @FilePath: /yt-devops/lib/components/yt_form/value_accessors/poi_value_accessors.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:reactive_forms/reactive_forms.dart';
// import 'package:xbr_gaode_navi_amap/search/entity/poi_result.dart';
import 'package:yt_devops/model/amap_poi.dart';

/// Represents a control value accessor that convert between data types
/// [Poi] and [String].
class PoiValueAccessor extends ControlValueAccessor<AmapPoi, String> {
  PoiValueAccessor();

  @override
  String modelToViewValue(AmapPoi? modelValue) {
    return modelValue == null ? '' : (modelValue.formattedAddress ?? '');
  }

  @override
  AmapPoi? viewToModelValue(String? viewValue) {
    return viewValue == null || viewValue.trim().isEmpty
        ? null
        : AmapPoi(formattedAddress: viewValue, latitude: 0, longitude: 0);
  }
}
